local awful = require("awful")
local wibox = require("wibox")
local gears = require("gears")
local theme = require("theme")
local dpi	= require("beautiful.xresources").apply_dpi


local topbar = {}


local function gap(v)
	return wibox.widget {
		left = dpi(v),
		widget  = wibox.container.margin,
	}
end


function topbar:setup(s)
	s.topbar = awful.wibar({
		screen   = s,
		position = "top",
		ontop    = false,
		type     = "dock",
		height   = theme.topbar_height,
		fg       = theme.topbar_fg, 
		bg       = theme.topbar_bg
	})
	s.topbar:setup {
		{
			require("widgets.layoutbox"):setup(s),
			gap(3),
			require("widgets.taglist"):setup(s),
			layout = wibox.layout.fixed.horizontal,
		},
		nil,
		{
			--require("widgets.tasklist"):setup(s),
			--require("widgets.music"):setup(),
			require("widgets.caps"):setup(),
			gap(15),
			require("widgets.indicator"):setup(),
			gap(3),
			require("widgets.weather"):setup(),
			gap(3),
			require("widgets.wifi"):setup(),
			gap(3),
			require("widgets.netspeed"):setup(),
			gap(3),
			require("widgets.mem"):setup(),
			gap(3),
			require("widgets.cpu"):setup(),
			gap(3),
			require("widgets.disk"):setup(),
			gap(3),
			require("widgets.volume"):setup(),
			gap(3),
			require("widgets.clock"):setup(),
			gap(3),
			require("widgets.taskpanel"):setup(),
			layout = wibox.layout.fixed.horizontal,
		},
		layout = wibox.layout.align.horizontal,
	}
end

--[[
function topbar:setup(s)
	s.topbar = awful.wibar({
		screen   = s,
		position = "top",
		ontop    = false,
		type     = "dock",
		height   = theme.topbar_height,
		fg       = theme.topbar_fg, 
		bg       = theme.topbar_bg
	})
	s.topbar:setup {
		{
			{
				require("widgets.wifi"):setup(),
				gap(3),
				require("widgets.netspeed"):setup(),
				gap(3),
				require("widgets.mem"):setup(),
				gap(3),
				require("widgets.cpu"):setup(),
				layout = wibox.layout.fixed.horizontal,
			},
			nil,
			{
				require("widgets.caps"):setup(),
				gap(3),
				require("widgets.indicator"):setup(),
				gap(3),
				require("widgets.layoutbox"):setup(s),
				gap(3),
				layout = wibox.layout.fixed.horizontal,
			},
			forced_width = dpi(806.5),
			layout = wibox.layout.align.horizontal,
		},
		require("widgets.taglist"):setup(s),
		{ 
			{
				gap(3),
				require("widgets.clock"):setup(),
				gap(3),
				layout = wibox.layout.fixed.horizontal,
			},
			nil,
			{
				--require("widgets.tasklist"):setup(s),
				--gap(3),
				--require("widgets.music"):setup(),
				--require("widgets.weather"):setup(),
				gap(3),
				require("widgets.disk"):setup(),
				gap(3),
				require("widgets.volume"):setup(),
				require("widgets.taskpanel"):setup(),
				layout = wibox.layout.fixed.horizontal,
			},
			forced_width = dpi(806.5),
			layout = wibox.layout.align.horizontal,
		},
		layout = wibox.layout.align.horizontal,
	}
end
--]]



return topbar
